home *** CD-ROM | disk | FTP | other *** search
/ NeXT Education Software Sampler 1992 Fall / NeXT Education Software Sampler 1992 Fall.iso / Mathematics / Notebooks / SigProc2.0 / Packages / SignalProcessing / Digital / ZSupport.m < prev    next >
Encoding:
Text File  |  1992-08-18  |  6.7 KB  |  229 lines

  1. (*  :Title:    Supporting Routines for the z-Transform  *)
  2.  
  3. (*  :Authors:    Brian Evans, James McClellan  *)
  4.  
  5. (*  :Summary:    *)
  6.  
  7. (*  :Context:    SignalProcessing`Digital`ZSupport`  *)
  8.  
  9. (*  :PackageVersion:  2.7    *)
  10.  
  11. (*
  12.     :Copyright:    Copyright 1989-1991 by Brian L. Evans
  13.         Georgia Tech Research Corporation
  14.  
  15.     Permission to use, copy, modify, and distribute this software
  16.     and its documentation for any purpose and without fee is
  17.     hereby granted, provided that the above copyright notice
  18.     appear in all copies and that both that copyright notice and
  19.     this permission notice appear in supporting documentation,
  20.     and that the name of the Georgia Tech Research Corporation,
  21.     Georgia Tech, or Georgia Institute of Technology not be used
  22.     in advertising or publicity pertaining to distribution of the
  23.     software without specific, written prior permission.  Georgia
  24.     Tech makes no representations about the suitability of this
  25.     software for any purpose.  It is provided "as is" without
  26.     express or implied warranty.
  27.  *)
  28.  
  29. (*  :History:    *)
  30.  
  31. (*  :Keywords:    normalized, z-transform, region of convergence    *)
  32.  
  33. (*  :Source:    *)
  34.  
  35. (*  :Warning:    *)
  36.  
  37. (*  :Mathematica Version:  1.2 or 2.0  *)
  38.  
  39. (*  :Limitation:  *)
  40.  
  41. (*
  42.     :Functions:      InvalidZTransformQ
  43.           InvalidInvZTransformQ
  44.           KeepNormalized
  45.           MakeZObject
  46.           ZForm
  47.           ZTransformQ
  48.           ZUpsampledQ
  49.           ZVariables
  50.  *)
  51.  
  52.  
  53.  
  54. (*  B E G I N     P A C K A G E  *)
  55.  
  56. BeginPackage[ "SignalProcessing`Digital`ZSupport`",
  57.           "SignalProcessing`Support`TransSupport`",
  58.           "SignalProcessing`Support`ROC`",
  59.           "SignalProcessing`Support`SigProc`",
  60.           "SignalProcessing`Support`SupCode`" ]
  61.  
  62.  
  63. If [ TrueQ[ $VersionNumber >= 2.0 ],
  64.      Off[ General::spell ];
  65.      Off[ General::spell1 ] ];
  66.  
  67.  
  68. (*  U S A G E     I N F O R M A T I O N  *)
  69.  
  70. InvalidZTransformQ::usage =
  71.     "InvalidZTransformQ[x] returns True if a call exists to \
  72.     the function MyZTransform in expression x; that is, True \
  73.     is returned if the result from a call to Z or ZTransform \
  74.     was not a valid Z transform."
  75.  
  76. InvalidInvZTransformQ::usage =
  77.     "InvalidInvZTransformQ[x] returns True if the result from a \
  78.     call to InvZTransform was not a valid inverse z-transform. \
  79.     This occurs when the object myinvz exists in expression x."
  80.  
  81. KeepNormalized::usage =
  82.     "KeepNormalized[zexpr, fun, z, args] keeps the z-transform \
  83.     expression zexpr in negative powers of z after the function \
  84.     fun is applied to zexpr and args as fun[zexpr, args]."
  85.  
  86. MakeZObject::usage =
  87.     "MakeZObject[l] and MakeZObject[l, zlist] converts the \
  88.     z-transform information in list l into the standard object \
  89.     form ZTransData[x, Rminus[rm], Rplus[rp], ZVariables[zlist]]. \
  90.     Here, x is the z-transform, rm is the lower bound on the \
  91.     region of convergence, rp is the upper bound on the region \
  92.     of convergence, and zlist is the list of z variables used in \
  93.     the transform."
  94.  
  95. ZForm::usage =
  96.     "ZForm[x] return True if the data packet x is tagged with \
  97.     either List or Transform and contains three elements."
  98.  
  99. ZTransformQ::usage =
  100.     "ZTransformQ[x] returns True if the datum x is of the form \
  101.     ZTransData[X, rm, rp, z], where X is the z-transform, rm is the \
  102.     Rminus component of the region of convergence, rp is the \
  103.     Rplus component of the region of convergence, and z is \
  104.     the variable(s) in the z-transform."
  105.  
  106. ZUpsampledQ::usage =
  107.     "ZUpsampledQ[f, n] returns True if the sequence f, as a function \
  108.     of n, has been upsampled. \
  109.     See UpsampleFactor."
  110.  
  111. (*  E N D     U S A G E     I N F O R M A T I O N  *)
  112.  
  113.  
  114. Begin["`Private`"]
  115.  
  116.  
  117. (*  E X T E N D     B U I L T - I N     R O U T I N E S  *)
  118.  
  119. (*  Denominator  *)
  120. ZTransData/: Denominator[ZTransData[fun_, a__]] := Denominator[fun]
  121.  
  122. (*  Factor  *)
  123. ZTransData/: Factor[ZTransData[fun_, a__]] := ZTransData[Factor[fun], a]
  124.  
  125. (*  Numerator  *)
  126. ZTransData/: Numerator[ZTransData[fun_, a__]] := Numerator[fun]
  127.  
  128. (*  Simplify  *)
  129. ZTransData/: Simplify[ZTransData[fun_, rm_, rp_, z_]] :=
  130.     Block [    {replace, zvars},
  131.         zvars = ToCollection[z];    (* strip off ZVariables head *)
  132.         replace = zvars ~ReplaceWith~ (zvars^-1);
  133.         ZTransData[Simplify[fun /. replace] /. replace, rm, rp, z] ]
  134.  
  135. (*  Together  *)
  136. ZTransData/: Together[ZTransData[fun_, rm_, rp_, z_]] :=
  137.     Block [    {replace, zvars},
  138.         zvars = ToCollection[z];    (* strip off ZVariables head *)
  139.         replace = zvars ~ReplaceWith~ (zvars^-1);
  140.         ZTransData[Together[fun /. replace] /. replace, rm, rp, z] ]
  141.  
  142.  
  143. (*  E X T E N D     D E F I N E D     R O U T I N E S  *)
  144.  
  145. (*  TheFunction  *)
  146. ZTransData/: TheFunction[ZTransData[x_, rm_, rp_, z_]] := x
  147.  
  148.  
  149. (*  O T H E R     S U P P O R T I N G     R O U T I N E S  *)
  150.  
  151. (*  InvalidZTransformQ, InvalidInvZTransformQ  *)
  152. invalid[x_, h_] := If [ SameQ[Head[x], head], flag = True ];
  153.  
  154. InvalidZTransformQ[x_] :=        (* flag is exterior package data *)
  155.     Block [    {head},
  156.         head = SignalProcessing`Digital`ZTransform`Private`MyZTransform;
  157.         flag = SameQ[Head[x], head];    (* exterior package data *)
  158.         If [ ! flag, Scan[invalid[#, head]&, x, Infinity] ];
  159.         flag ]
  160.  
  161. InvalidInvZTransformQ[x_] :=        (* flag is exterior package data *)
  162.     Block [    {head},
  163.         head = SignalProcessing`Digital`InvZTransform`Private`MyInvZTransform;
  164.         flag = SameQ[Head[x], head];
  165.         head = SignalProcessing`Digital`InvZTransform`Private`myinvz;
  166.         If [ ! flag, flag = SameQ[Head[x], head] ];
  167.         If [ ! flag, Scan[invalid[#, head]&, x, Infinity] ];
  168.         flag ]
  169.  
  170. (*  KeepNormalized  *)
  171. (*  Maintain z-transform expressions in terms of z^-1.  *)
  172. KeepNormalized[e_, f_, z_, args___] :=
  173.     Block [ {newexpr, zexpr},
  174.         zexpr = e /. ReplaceWith[z, z^-1];
  175.         newexpr =  f[zexpr, args];
  176.         newexpr /. ReplaceWith[z, z^-1] ]
  177.  
  178. (*  MakeZObject  *)
  179. MakeZObject[ZTransData[x_, rm_, rp_, z_]] :=
  180.     ZTransData[x, rm, Rplus[ GetRPlus[rp] ], z]
  181. MakeZObject[x_List] :=
  182.     ZTransData[ x[[1]], Rminus[ x[[2]] ], Rplus[ InfCheck[x[[3]]] ] ]
  183. MakeZObject[x_, z_] :=
  184.     ZTransData[ x[[1]], Rminus[ x[[2]] ],
  185.             Rplus[ InfCheck[x[[3]]] ], ZVariables[ z ] ] /;
  186.     ZForm[x]
  187.  
  188. Format[ MakeZObject[a__] ] := "-Incomplete z-Transform-"
  189.  
  190. (*  ZForm  *)
  191. ZForm[Transform[x_, rm_, rp_]] := True
  192. ZForm[List[x_, rm_, rp_]] := True
  193.  
  194. (*  ZTransformQ  *)
  195. ZTransformQ[x_] := SameQ[Head[x], ZTransData]
  196.  
  197. (*  ZUpsampledQ  *)
  198. ZUpsampledQ[f_, n_] :=
  199.     Block [    {upindex},
  200.         upindex = UpsampleFactor[f, n];      (* returns pos & neg nums *)
  201.         Implies[ NumberQ[N[upindex]], N[Abs[upindex] > 1]] ]
  202.  
  203.  
  204. (*  E N D     P A C K A G E  *)
  205.  
  206. End[]
  207. EndPackage[]
  208.  
  209. If [ TrueQ[ $VersionNumber >= 2.0 ],
  210.      On[ General::spell ];
  211.      On[ General::spell1 ] ];
  212.  
  213.  
  214. (*  H E L P     I N F O R M A T I O N  *)
  215.  
  216. Block [    {newfuns},
  217.     newfuns =
  218.       { InvalidZTransformQ,    InvalidInvZTransformQ,    KeepNormalized,
  219.         MakeZObject,    ZUpsampledQ,        ZTransformQ,
  220.         ZVariables };
  221.     Combine[ SPfunctions, newfuns ];
  222.     Apply[ Protect, newfuns ] ]
  223.  
  224.  
  225. (*  E N D I N G     M E S S A G E  *)
  226.  
  227. Print["Supporting routines for the z-transform rule bases are loaded."]
  228. Null
  229.